import { ref, onMounted, onUnmounted, watch, reactive } from 'vue'

import { getButtonEnterStatus, getButtonFindStatus, getButtonClear, getLoanButtonFindStatus } from '@/api/system/common'
import { useStore } from '@/store';
import { useRoute, useRouter } from 'vue-router';

/**
 * @description 用户网络是否可用
 * */
export function useButtonStatus() {

  // getButtonEnterStatus
  const store = useStore()
  const route = useRoute()
  const router = useRouter()

  const buttonRef = reactive({

  })

  const getSwitchClearButton = async (opt) => {
    const res = await getButtonClear({
      buttonCode: opt.buttonCode,
      code: opt.code,
      proactive: 1
    })
    return res
  }

  const getSwitchEnterButton = async (opt) => {
    const res = await getButtonEnterStatus({
      buttonCode: opt.buttonCode,
      code: opt.code,
      proactive: 1
    })
    return res
  }
  const getSwitchChangeButton = async (opt) => {
    const res = await getButtonFindStatus({
      buttonCode: opt.buttonCode,
      code: opt.code,
      proactive: 1
    })
    return res
  }

  const getSwitchChangeLoanButton = async (opt) => {
    const res = await getLoanButtonFindStatus({
      buttonCode: opt.buttonCode,
      code: opt.code,
      proactive: 1
    })
    return res
  }

  // 判断进入路由跳转页面
  const enterUrl = (url, buttonCode, code?) => {
    getSwitchEnterButton({ buttonCode: buttonCode, code: code }).then(() => {
      router.replace(url)
    })
  }

  onMounted(() => {


  })
  onUnmounted(() => {
    // 移除监听网络状态的变化

  })


  return {
    getSwitchClearButton,
    getSwitchEnterButton,
    getSwitchChangeButton,
    getSwitchChangeLoanButton,
    enterUrl
  }
}
